home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / netlib / _dup2.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  1KB  |  69 lines

  1. RCS_ID_C="$Id: _dup2.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      _dup2.c - duplicate a file descriptor (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <ios1.h>
  11. #include <fcntl.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #define USE_BUILTIN_MATH
  15. #include <string.h>
  16. #include <errno.h>
  17. #include <dos/dos.h>
  18. #include <proto/dos.h>
  19.  
  20. #include <bsdsocket.h>
  21.  
  22. /****** net.lib/dup2 **********************************************************
  23.     SEE ALSO
  24.         dup()
  25. *******************************************************************************
  26. */
  27.  
  28.  
  29. int
  30. __dup2(int old_fd, int new_fd)
  31. {
  32.   struct UFB *ufb;
  33.   int ufbflg;
  34.  
  35.   /*
  36.    * Check if there is nothing to do
  37.    */
  38.   if (old_fd == new_fd)
  39.     return old_fd;
  40.  
  41.   /*
  42.    * Check for the break signals
  43.    */
  44.   __chkabort();
  45.  
  46.   __close(new_fd);
  47.  
  48.   /*
  49.    * Find the ufb * for the old FD
  50.    */
  51.   if ((ufb = __chkufb(old_fd)) == NULL) {
  52.     errno = EBADF;
  53.     return -1;
  54.   }
  55.  
  56.   ufbflg = ufb->ufbflg;
  57.  
  58.   /* 
  59.    * The brain dead UFB system won't allow duplicating ordinary files
  60.    */
  61.   if ((ufbflg & UFB_SOCK) == UFB_SOCK) {
  62.     return Dup2Socket(old_fd, new_fd);
  63.   } else {
  64.     errno = EBADF;
  65.     return -1;
  66.   }
  67.  
  68. }
  69.